/***************************************************
> Copyright (C) 2024 ==LENA== All rights reserved.
> File Name: 作业7.12晚1.c
> Author: lena
> Mail:lena_li@126.com
> Created Time: 2024年07月12日 星期五 02时55分30秒
***************************************************/
// 解析报文: PackType:Request,TransCode:D001
    
  //  得到结果：
    //    Request
      //  D001
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 100
//寻找

char *num(char *erg,char *des);
char *get(char *dest,char *src);
char *str(char *s1,char ch);
int main(int argc,const char* argv[])
{
	char *result =NULL;
	//
	char *dest =(char *)malloc(sizeof(char)*SIZE);
	memset(dest,0,SIZE*sizeof(char));
	strcpy(dest,"PackType:Request,TransCode:D001");
	//
	char *src = (char*)malloc(sizeof(char)*SIZE);
	memset(src,0,SIZE*sizeof(char));
	
	result=get(dest,src);
	puts(result);

	result=NULL;

	char *des =(char *)malloc(sizeof(char)*SIZE);
	memset(des,0,SIZE*sizeof(char));
	
	result=num(dest,des);
	
	puts(result);
	
	free(des);
	des=NULL;
	free(dest);
	dest=NULL;
	free(src);
	src=NULL;
	return 0;
}
char *get(char *dest,char *src){
	char *start=NULL;
	char *end=NULL;
	start=strstr(dest,"PackType:");
	start+=strlen("PackType:");
	end=str(start,',');
	strncpy(src,start,end-start);
	return src;
}

char *num(char *erg,char *des){
	char *srart=NULL;
	char *enmd=NULL;
	srart=strstr(erg,"TransCode:");
	srart+=strlen("TransCode:");
	enmd=str(srart,'\0');
	strncpy(des,srart,enmd-srart);
	return des;
}
char* str(char* s1,char ch)
{
	char *end = s1;
	int i = 0;
	while(1)
	{
		if(*(s1+i)==ch)
		{
			//指针赋值
			end = s1+i;
			break;
		}
		i++;
	}
	return end;
}
